home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / host / Host_SetFile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  1.6 KB  |  61 lines

  1. /* 
  2.  * Host_SetFile.c --
  3.  *
  4.  *    Source code for the Host_SetFile library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: Host_SetFile.c,v 1.1 88/06/30 11:06:48 ouster Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <stdio.h>
  21. #include <host.h>
  22. #include <hostInt.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26.  
  27. /*
  28.  *-----------------------------------------------------------------------
  29.  *
  30.  * Host_SetFile --
  31.  *
  32.  *    Change the file being used to fetch info.
  33.  *
  34.  * Results:
  35.  *    Zero is returned if all went well.  If an error occurred,
  36.  *    then -1 is returned and errno tells exactly what went wrong.
  37.  *
  38.  * Side Effects:
  39.  *    The old file is closed. A Host_Start need not be given as the
  40.  *    file will be open already.
  41.  *
  42.  *-----------------------------------------------------------------------
  43.  */
  44.  
  45. int
  46. Host_SetFile(fileName)
  47.     char          *fileName;    /* File to use as the database */
  48. {
  49.     if (hostFile != (FILE *) NULL) {
  50.     fclose(hostFile);
  51.     }
  52.     hostFile = fopen(fileName, "r");
  53.     if (hostFile == (FILE *) NULL) {
  54.     return -1;
  55.     } else {
  56.     hostFileName = malloc((unsigned) (strlen(fileName) + 1));
  57.     strcpy(hostFileName, fileName);
  58.     }
  59.     return 0;
  60. }
  61.